#!/bin/bash
CWD=$(pwd)
IMG_PATH=$CWD/app/asserts/images
GEN_PATH=$CWD/app/asserts/generated
COVERT=$CWD/tools/scripts/lv_utils/img_conv_core.php

#
total_cnt=0

# re-generate picture resource
rm -rf $GEN_PATH

mkdir $GEN_PATH -p

cd $GEN_PATH

echo "  ----> starting to covert images ..."
for dir in $(ls $IMG_PATH)
do
    mkdir -p $dir
    cd $dir
    echo "    --> images under $dir:"
    files=$(ls $IMG_PATH/$dir)
    currnt_cnt=0
    for file in $files
    do
        total_cnt=$((total_cnt + 1))
        currnt_cnt=$((currnt_cnt + 1))
        echo "      --> [$currnt_cnt] convert $file to ${file%.*}.c"
        php $COVERT "name=${file%.*}&img=$IMG_PATH/$dir/$file&format=c_array&cf=true_color_alpha"
    done
    cd ..
done

echo "  ----> $total_cnt images converted."

